package com.hubstc.book_borrow.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface BorrowMapper {

    @Insert("insert into borrow (readerId,bookId,borrowDate) values (#{readerId},#{bookId},#{borrowDate});")
    void addBorrow(String readerId, String bookId, LocalDate borrowDate);

    @Update("update borrow set returnDate = #{returnDate} where borrowId=#{borrowId};")
    void returnBook(int borrowId,LocalDate returnDate);
    
    @Select("select borrow.*,book.bookName from borrow " +
            "inner join book on borrow.bookId=book.bookId " +
            "inner join reader on borrow.readerId=reader.readerId " +
            "where borrow.readerId=#{readerId};")
    Map<String,Object> selectBorrow(String readerId);

}
